<%@page import="com.beaut.project.util.StaticData"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
	String is_closed = request.getParameter("is_closed");
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String status = request.getParameter("status") == null ? "0" : request.getParameter("status");
%>
<html>
	<head>
		<title>预算调整</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageGDChangeAssume?gd_id=<%=gd_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'工单主键',field:'gd_id',hidden:true}
				]],
				columns:[[
					{title:'申请日期',field:'operation_date',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:150,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:100,align:'center'},
					{title:'审批查看',field:'shenpichakan',width:80,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status != '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_CHANGE_ASSUME_SHENPI%>")+"','"+rowData.id+"');\"/>";
						}
						return "";
			        }},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEdit(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteRow('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEdit(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
						}
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEdit(2,'"+rowData.id+"');\"/>";
	
					}}
				]],
				<%if(!"1".equals(is_closed)){%>
					<%if(Integer.parseInt(status) <= StaticData.WORKING){%>
					toolbar:[{
						id:'add',
						text:'申请调整',
						disabled:false,
						iconCls:'icon-add',
						handler:function(){
							addOrEdit(0);
						}
					}],
					<%}%>
				<%}%>
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function shenpi(obj,id){
		  var flowBusinessUrl ="<%=contextPath%>/springViews/gd/addOrEditChangeAssume.jsp?isShow=1&gd_id=<%=gd_id%>&change_id="+id;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_CHANGE_ASSUME_SHENPI%>")+"&businessId="+id;
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath%>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
		}
		
		function addOrEdit(type,id){
			if(type == 0){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditChangeAssume.jsp?callback=rtCallBack&gd_id=<%=gd_id%>",1000, 800);
			}
			if(type == 1){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditChangeAssume.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&change_id="+id,1000, 800);
			}
			if(type == 2){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditChangeAssume.jsp?isShow=1&gd_id=<%=gd_id%>&change_id="+id,1000, 800);
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteRow(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteChangeAssume",
						data:"change_id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
	</script>
	<body>
		<div id="table" data-options="fit:true" ></div>
	</body>
</html>
